#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<string.h>
#include<fcntl.h>
#include<unistd.h>

void static setfl(int, int);

int main(void){
	int fd;
	
	printf("O_RDWR   : %d\n", O_RDWR);
	printf("O_RDONLY : %d\n", O_RDONLY);
	printf("O_WRONLY : %d\n", O_WRONLY);
	printf("O_APPEND : %d\n", O_APPEND);
	printf("O_CREAT  : %d\n", O_CREAT);
	printf("O_SYNC   : %d\n", O_CREAT);

	setfl(STDOUT_FILENO, O_SYNC);
}

void static setfl(int fd, int flags){
	int val;
	if((val = fcntl(fd, F_GETFL, 0)) < 0){
		perror("fcntl F_GETFL error");
		exit(1);
	}
	
	printf("%d | %d \n", val, flags);

	val |= flags;

	if(fcntl(fd, F_GETFL, val) < 0){
		perror("fcntl F_GETFL error");
		exit(1);
	}

}
